package com.lagou.pojo;

import com.lagou.binding.MapperRegistry;
import com.lagou.sqlsession.DefaultSqlSession;
import com.lagou.sqlsession.SqlSession;

import javax.sql.DataSource;
import java.util.HashMap;
import java.util.Map;

public class Configuration {

    private DataSource dataSource;
    private Map<String, MappedStatement> mappedStatementMap = new HashMap<>();
    protected final MapperRegistry mapperRegistry = new MapperRegistry(this);


    public DataSource getDataSource() {
        return dataSource;
    }

    public void setDataSource(DataSource dataSource) {
        this.dataSource = dataSource;
    }

    public Map<String, MappedStatement> getMappedStatementMap() {
        return mappedStatementMap;
    }

    public void setMappedStatementMap(Map<String, MappedStatement> mappedStatementMap) {
        this.mappedStatementMap = mappedStatementMap;
    }

    public <T> T getMapper(Class<T> type, SqlSession sqlSession) {
        return mapperRegistry.getMapper(type, sqlSession);
    }

    public <T> boolean hasMapper(Class<T> boundType) {
        return this.mapperRegistry.hasMapper(boundType);
    }

    public <T> void addMapper(Class<T> boundType) {
        this.mapperRegistry.addMapper(boundType);
    }
}
